#pragma once

#include "VertexBuffer.hpp"
#include "Shader.hpp"
#include "StaticModel.hpp"

#include <GLFW/glfw3.h>

#include <list>

// Helper class, that can be used to run code at a specific point during member initialization
class InitHelper
{
public:
	template<typename lambda> InitHelper(lambda& l)
	{
		l();
	}
};


class SceneRenderer
{
public:
	SceneRenderer();

	void Run();
	static std::string PrintControls();
private:
	void LoadTerrainTexture(std::string folder);
	void Render();
	void ProcessInput(float t);
	mat4 GetCamera();
	mat4 GetProjection();

	GLFWwindow* m_Window;
	InitHelper InitFirst;

	VertexBuffer m_TerrainBuffer;
	VertexBuffer m_SkydomeBuffer;
	Shader m_TerrainShader;
	Shader m_SkydomeShader;
	unsigned int m_OriginalTexture;
	unsigned int m_LowFreqTexture;
	unsigned int m_HighFreqTexture;
	unsigned int m_SkydomeTexture;
	unsigned int m_mode; // tiling / detail mapping
	float m_Tiling; // how often the smaller texture is tiled over the terrain
	std::list<std::string> m_TextureCycle;
	std::list<std::string>::iterator m_CurrentTextureInCycle;
	bool m_TextureJustToggled;

	// camera:
	float m_CameraMoveSpeed;
	float m_CameraRotateSpeed;
	float m_CameraZoomSpeed;
	float m_CameraPerspective;

	ivec2 m_WindowResolution;
	float m_Distance;
	vec2 m_ViewAngle;
	vec3 m_CameraLookAt;
	vec2 m_MousePos; // needed to compute the cursor delta
};
